﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EstateNuke.Data;
using Gizmox.WebGUI.Forms;

namespace EstateNuke.BusinessSystem
{
    public class EstateNukeControl : UserControl
    {
        protected EstateNukeCore DBContext
        {
            get
            {
                EstateNukeCore context = Context["DBContext"] as EstateNukeCore;
                if (context == null)
                {
                    context = new EstateNukeCore();
                    Context["DBContext"] = context;
                }

                return context;
            }
            set
            {
                Context["DBContext"] = value;
            }
               
        }
        protected User CurrentUser
        {
            get
            {
                User user = Context["CurrentUser"] as User;

                return user;
            }
            set
            {
                Context["CurrentUser"] = value;
            }
        }
        protected  IList<Project> CurrentProjects
        {
            get
            {
                if (CurrentUser.Role == DBContext.RoleEnum.Administrator || CurrentUser.Role == DBContext.RoleEnum.GeneralManager)
                {
                    return DBContext.GetAllProjects();
                }
                else
                {
                    return CurrentUser.Projects;
                }
            }
        }
    }
}